import { createStore } from 'vuex'

const store = createStore({
    state: {
		userToken:uni.getStorageSync('MH_TOKEN') || null,
		encryptedAccessToken:uni.getStorageSync('encryptedAccessToken') || null,
		config:uni.getStorageSync('SDTZRJCONFIG') || null,
		projects:uni.getStorageSync('SDTZRJPROJECTS') || null,
		assetTypes:uni.getStorageSync('SDTZRJASSETTYPES') || null,
		userInfo:null,
		collectLaod:false,
		scene:'',
		news:''
	},
    mutations: {
		LOGIN_OUT(state, data) {
			state.userToken = ''
			state.userInfo = ''
			uni.removeStorageSync('MH_TOKEN')
		},
		SET_COLLECTLAOD(state, data) {
			state.collectLaod = data
		},
		SET_SCENE(state, data) {
			state.scene = data
		},
		SET_NEWS(state, data) {
			state.news = data
		},
		SET_USERTOKEN(state, data) {
			state.userToken = data.token
			if(JSON.parse(data.isRemember)){
				uni.setStorageSync('MH_TOKEN', data.token)
			}
		},
		SET_ETOKEN(state, data) {
			state.encryptedAccessToken = data
			uni.setStorageSync('encryptedAccessToken', data)
		},
		SET_USERINFO(state, data) {
			state.userInfo = data
			uni.setStorageSync('MH_userInfo', data)
		},
		SET_CONFIG(state, data) {
			state.config = data
			uni.setStorageSync('SDTZRJCONFIG', data)
		},
		SET_PROJECTS(state, data) {
			state.projects = data
			uni.setStorageSync('SDTZRJPROJECTS', data)
		},
		SET_ASSETTYPES(state, data) {
			state.assetTypes = data
			uni.setStorageSync('SDTZRJASSETTYPES', data)
		}
	},
    actions: {}
})

export default store